//
//  UtilsMacro.h
//  Tools
//
//  Created by han on 2019/1/11.
//  Copyright © 2019 han. All rights reserved.
//

#ifndef UtilsMacro_h
#define UtilsMacro_h

//debug
#ifdef DEBUG
#define DebugLog(s, ...) NSLog(@"%s(%d): %@", __FUNCTION__, __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__])
#else
#define DebugLog(s, ...)
#endif

//version
#define kVersion [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]
#define kVersionBuild  [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]

//frame
#define kScreen_Bounds [UIScreen mainScreen].bounds
#define kScreen_Width CGRectGetWidth([UIScreen mainScreen].bounds)
#define kScreen_Height CGRectGetHeight([UIScreen mainScreen].bounds)
#define kApplicationStatusHeight  CGRectGetHeight([[UIApplication sharedApplication]statusBarFrame])
#define kWidth(var) (var/375.0*kScreen_Width)
#define kPhoneWidthRatio SCREEN_WIDTH/375
#define kPhoneHeightRatio SCREEN_HEIGHT/667

//safeArea
#define kWindowSafeAreaBottom \
({CGFloat t=0;if (@available(iOS 11.0, *)){t=[UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;}else{t=0;}t;})
#define kWindowSafeAreaTop \
({CGFloat t=0;if (@available(iOS 11.0, *)){t=[UIApplication sharedApplication].delegate.window.safeAreaInsets.top;}else{t=0;}t;})
#define SafeAreaBottomHeight(view) \
({CGFloat t=0;if(@available(iOS 11.0, *)){t=view.safeAreaInsets.bottom;}else{t=0;}t;})
#define SafeAreaTopHeight(view) \
({CGFloat t=0;if(@available(iOS 11.0, *)){t=view.safeAreaInsets.top;}else{t=0;}t;})

//color
#define kColorFromHex(rgbValue) [UIColor colorWithRed:((float)rgbValue & 0xFF0000 >> 16) green:((float)rgbValue & 0xFF00 >> 8) blue:((float)rgbValue & 0xFF) alpha:1.0]
#define kColor(r,g,b) [UIColor colorWithRed:r/255.f green:g/255.f blue:b/255.f alpha:1]
#define kColorRGBA(r,g,b,a)  [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]

// 调整scrollView的视图偏移
#define AdjustsScrollViewInsetNever(controller,view) \
if(@available(iOS 11.0, *)) {view.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;} else if([controller isKindOfClass:[UIViewController class]]) {controller.automaticallyAdjustsScrollViewInsets = false;}

//weak reference
#define Weakly(var, weakVar) __weak __typeof(&*var) weakVar = var

// block
#define BLOCK_EXEC(block, ...) if (block) { block(__VA_ARGS__); };




#endif /* UtilsMacro_h */

/*
 __VA_ARGS__:可变参数的宏
 ##：粘合剂
 */
